{% extends "organizations/admin/base.html" %}

{% load i18n gravatar %}
{% load static %}
{% load humanize %}

{% block title %}{% trans "Organization Subscription" %}{% endblock %}

{% block organization-admin-subscription %}active{% endblock %}

{% block edit_content_header %}Subscription{% endblock %}

{% block edit_content %}
  <div>
    {% if stripe_subscription.status == 'trialing' %}
      <ul class="notifications">
        <li class="notification notification-info">
          {% url 'pricing' as pricing_url %}
          {% blocktrans trimmed with pricing_url=pricing_url %}
          You are currently on a trial.
          Please choose a <a href="{{ pricing_url }}">paid plan</a> that fits your organization
          prior to the end of your trial.
          Upgrade your account by clicking on <strong>Manage Subscription</strong> below.
          {% endblocktrans %}
        </li>
      </ul>
    {% endif %}

    {% if stripe_subscription and stripe_subscription.status != 'canceled' %}
    <dl>
      <dt>{% trans "Plan" %}:</dt>
      <dd>
        <span class="subscription-plan-name">
          {{ main_product.stripe_price.product.name }}
        </span>
        <span class="subscription-plan-price">
          ({{ main_product.stripe_price.human_readable_price }})
        </span>
      </dd>

      {% if extra_products %}
        <dt>{% trans "Extra products:" %}</dt>
        {% for extra_product in extra_products %}
        <dd>
          <span class="subscription-plan-name">
            {{ extra_product.stripe_price.product.name }}
          </span>
          <span class="subscription-plan-price">
            ({{ extra_product.stripe_price.human_readable_price }})
          </span>
          {% if extra_product.quantity > 1 %}
            <span>
              (x{{ extra_product.quantity }})
            </span>
          {% endif %}
        </dd>
        {% endfor %}
      {% endif %}

      {% if features %}
      <dt>{% trans "Features:" %}</dt>
      <dd>
        {% for feature in features %}
          <span class="subscription-plan-{{ feature.type }}" style="display: block;">
            {{ feature.get_description }}
          </span>
        {% endfor %}
      </dd>
      {% endif %}

      {% if stripe_subscription.start_date %}
        <dt>{% trans "Signed up" %}:</dt>
        <dd>
          {# Translators: this is the subscription start date, used here as "4 days ago" or "5 months ago" #}
          {% blocktrans with time_since_signup=stripe_subscription.start_date|timesince trimmed %}
            {{ time_since_signup }} ago
          {% endblocktrans %}
        </dd>
      {% endif %}

      <dt>{% trans "Subscription status" %}:</dt>
      <dd>
        {{ stripe_subscription.get_status_display }}
      </dd>

      {% if stripe_subscription.status == 'trialing' and stripe_subscription.trial_end %}
        <dt>{% trans "Trial ends" %}:</dt>
        <dd>
          {{ stripe_subscription.trial_end|date:"SHORT_DATE_FORMAT" }}
        </dd>
      {% elif subscription_end_date %}
        <dt>{% trans "Subscription ends" %}:</dt>
        <dd>
            {{ subscription_end_date|date:"SHORT_DATE_FORMAT" }}
        </dd>
      {% endif %}
    </dl>

    <form method="post" action="{% url "stripe_customer_portal" organization.slug %}">
      {% csrf_token %}
      <button>
        <span>
          {% trans "Manage Subscription" %}
        </span>
      </button>
      <span class="helptext">
        {% trans "Use the button above to see past invoices, change your plan, and update your billing information." %}
      </span>
    </form>

    {% else %}
      {# Allow users to create a new subscription if the current one was canceled. #}
      <p class="help_text">
        {% url 'pricing' as pricing_url %}
        {% blocktrans trimmed with pricing_url=pricing_url %}
        <strong>You don't currently have an active subscription</strong>.
        You must create a subscription for a <a href="{{ pricing_url }}">paid plan</a> that fits your organization to continue using Read the Docs for Business.
        {% endblocktrans %}
      </p>
      <form action="" method="post">
        {% csrf_token %}
        {{ form.as_p }}
        <input id="submit" type="submit" value="{% trans "Create Subscription" %}" />
      </form>
    {% endif %}

 </div>
{% endblock %}
